

alter trigger [dbo].[tft_cashdaybook_au] on [dbo].[tft_cashdaybook] 
after update 
as   
begin
  set nocount on

  declare @naccountid int, @oaccountid int
  declare cur_tft_cashdaybook cursor local forward_only static optimistic 
  for select distinct n.accountid,o.accountid from inserted n,deleted o where n.daybookid=o.daybookid
  open cur_tft_cashdaybook
  fetch next from cur_tft_cashdaybook into @naccountid,@oaccountid
  while @@fetch_status = 0
  begin
    exec p_cashdaybook_sumbalance @naccountid   
    if @naccountid<>@oaccountid
      exec p_cashdaybook_sumbalance @oaccountid       
    fetch next from cur_tft_cashdaybook into @naccountid,@oaccountid
  end
ERR:  
  close cur_tft_cashdaybook
  deallocate cur_tft_cashdaybook     
    
end
